// 中心到访统计分析
var day_stamp = "";

function datetimeHandler()
{
}

//页面载入初始化
$( "body" ).ready( function( e )
{
	day_stamp=$("#start_date").val();
	try
	{
		if( typeof ( eval( "init" ) ) == "function" )
			eval( "init();" );
	}
	catch( e )
	{
	}

	// 初始化
	init_td_hover();
} );

/**
 * 根据指定的类型设置当前表单所显示的时间范围
 * 
 * @param flag
 *            <ul>
 *            <li>-1：上一周</li>
 *            <li>0：本周</li>
 *            <li>1：下一周</li>
 *            </ul>
 */
function cdatetime( flag )
{
	var ds = day_stamp.split( "-" );
	var d = new Date();
	d.setFullYear( parseInt( ds[ 0 ] ), parseInt( ds[ 1 ] ) - 1, parseInt( ds[ 2 ] ) );

	var week = d.getDay();
	var ms = d.getTime();
	var kd = 0;

	week = week == 0 ? 7 : week;
	
	if( flag == -1 )
	{
		kd = week * -1;
		d.setTime( ms + kd * 86400000 );
	}
	else if( flag == 1 )
	{
		kd = 8 - week;
		d.setTime( ms + kd * 86400000 );
	}
	else if( flag == 2 )
	{
		window.location.reload();
		return;
	}
	else
	{
		kd = 0;
		d = new Date();
	}
	var start_date = (d.getFullYear() + "-" + ( d.getMonth() + 1 ) + "-" + d.getDate());
	location.href = "?start_date="+start_date+"&flag="+flag;
}

function url_param( u, p )
{
	var up = param( u );
	var url = u.replace( /(.*?)\?(.*?)/, "$2" );
	url = u.replace( "?" + url, "" );

	if( typeof ( p ) == "object" )
	{
		for( var attr in p )
		{
			up[ attr ] = p[ attr ];
		}
	}

	var ps = [];

	for( var attr in up )
	{
		ps.push( attr + "=" + up[ attr ] );
	}

	return url + "?" + ps.join( "&" );
}

function init_td_hover()
{
	// 单元格样式处理
	$( "#reservelst" ).find( "td" ).each(
			function( id )
			{
				$( this ).hover(
						function()
						{
							$( this ).parent().css( "background-color", "#D8A5CC" );
							$( this ).css( "background-color", "#edf" );

							var ts = $( this ).parent().find( ":first" ).add(
									$( "#reservelst tr:first th" ).eq( $( this ).index() ) );
							ts.css( { "background-color": "#D8A5CC", "color": "#fff" } );
						},
						function()
						{
							$( this ).parent().css( "background-color", "" );
							$( this ).css( "background-color", "" );

							var ts = $( this ).parent().find( ":first" ).add(
									$( "#reservelst tr:first th" ).eq( $( this ).index() ) );
							ts.css( { "background-color": "", "color": "" } );
						} );
			} );

	// 表格行背景
	setTableRowBackColor( $( "#reservelst" ) );

}

//为表格行添加交替背景色
function setTableRowBackColor( table )
{
	var trs = table.find( "tr:visible[class!=fields]" );

	trs.each( function( id )
	{
		$( this ).attr( "class", id % 2 == 0 ? "even_row" : "odd_row" );
	} );
}
